package com.chezai.client.utils;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

public class ToastUtil {

    public static void showToast(Context ctx, Object obj) {
        Toast mToast = null;
        if (ctx == null) {
            return;
        }
        if (null != obj && obj instanceof Integer) {
            int messageIndex = Integer.parseInt(obj.toString());
            mToast = Toast.makeText(ctx, messageIndex, Toast.LENGTH_SHORT);
        } else if (null != obj && obj instanceof String) {
            mToast = Toast.makeText(ctx, obj.toString(), Toast.LENGTH_SHORT);
        }
        if (mToast != null)
            mToast.show();
    }

    public static void showLongToast(Context ctx, Object obj) {
        Toast mToast = null;
        if (ctx == null) {
            return;
        }
        if (null != obj && obj instanceof Integer) {
            int messageIndex = Integer.parseInt(obj.toString());
            mToast = Toast.makeText(ctx, messageIndex, Toast.LENGTH_LONG);
        } else if (null != obj && obj instanceof String) {
            mToast = Toast.makeText(ctx, obj.toString(), Toast.LENGTH_LONG);
        }
        if (mToast != null)
            mToast.show();
    }

    public static Toast showToast(Context ctx, String tips, int lastTime) {
        Toast mToast = Toast.makeText(ctx, tips, lastTime);
        mToast.setText(tips);
        mToast.show();
        return mToast;
    }

    public static Toast showToastCenter(Context ctx, Object obj) {
        return showToastCenter(ctx, obj, Toast.LENGTH_SHORT);
    }

    public static Toast showToastCenter(Context ctx, Object obj, int lastTime) {
        Toast mToast = null;
        if (null != obj && obj instanceof Integer) {
            int messageIndex = Integer.parseInt(obj.toString());
            mToast = Toast.makeText(ctx, messageIndex, lastTime);
        } else if (null != obj && obj instanceof String) {
            mToast = Toast.makeText(ctx, obj.toString(), lastTime);
        }
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.show();
        return mToast;
    }

}
